/*
 * Tablero.java
 *
 * Created on 30 de marzo de 2006, 04:51 AM
 */
package gui;

import Multimedia.MediaSonido;
import conexion.SocketListener;
import conexion.SocketServer;
import java.awt.Color;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javazoom.jlgui.basicplayer.BasicPlayerException;
import mundo.Baraja;
import mundo.Carta;

/**
 *
 * @author  Arquitectura
 */
public class Tablero extends javax.swing.JFrame implements SocketListener {

    private SocketServer socket;
    private Baraja baraja;
    private ArrayList<Carta> juego;
    private ArrayList<Carta> alfitrion;
    private ArrayList<Carta> jugador1;
    private ArrayList<Carta> jugador2;
    private ArrayList<Carta> jugador3;
    private ArrayList<Carta> jugada;
    private String s1;
    private double puntosAlfitrion;
    private double puntosJugador1;
    private int empates;
    private InformeJuego ij;
    private MediaSonido sonidoLogin;
    private Home gc;

    /** Creates new form Tablero */
    public Tablero() {

        initComponents();
        xPnlFondo pnlFondo = new xPnlFondo(9);
        this.add(pnlFondo);
        this.pack();
        this.setSize(800, 635); //El 635 depende (alto) depende del Skin usado.
        this.setLocationRelativeTo(null);

        s1 = "";
        baraja = new Baraja();
        juego = new ArrayList<Carta>();
        alfitrion = new ArrayList<Carta>();
        jugador1 = new ArrayList<Carta>();
        jugador2 = new ArrayList<Carta>();
        jugador3 = new ArrayList<Carta>();
        jugada = new ArrayList<Carta>();
        puntosAlfitrion = 0;
        puntosJugador1 = 0;
        empates = 0;
        //this.iniciar(1414);

        MediaSonido testca = new MediaSonido();
        try {

            testca.loadFile("C:/Documents and Settings/Arquitectura/Escritorio/SongInicioPartida.mp3");
            testca.play();

        } catch (BasicPlayerException ex) {
            Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public Tablero(MediaSonido sonidoLoginEntrada, Home hm) {

        initComponents();
        sonidoLogin = sonidoLoginEntrada;

        xPnlFondo pnlFondo = new xPnlFondo(9);
        this.add(pnlFondo);
        this.pack();
        this.setSize(800, 635); //El 635 depende (alto) depende del Skin usado.
        this.setLocationRelativeTo(null);
            this.gc=hm;
        //Relocalizar los objetos.


        s1 = "";
        baraja = new Baraja();
        juego = new ArrayList<Carta>();
        alfitrion = new ArrayList<Carta>();
        jugador1 = new ArrayList<Carta>();
        jugador2 = new ArrayList<Carta>();
        jugador3 = new ArrayList<Carta>();
        jugada = new ArrayList<Carta>();
        puntosAlfitrion = 0;
        puntosJugador1 = 0;
        empates = 0;
//        //this.iniciar(1414);


        try {
            sonidoLogin.stop();
            sonidoLogin.loadFile("C:/Documents and Settings/Arquitectura/Escritorio/SongInicioPartida.mp3");
            sonidoLogin.play();

        } catch (BasicPlayerException ex) {
            Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jlJugador1 = new javax.swing.JLabel();
        jlJugador2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jbAbandonar = new javax.swing.JButton();
        jbConsultar = new javax.swing.JButton();
        jbRealizar = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jProgressBar1 = new javax.swing.JProgressBar();
        jPanel1 = new javax.swing.JPanel();
        jcCaracteristica = new javax.swing.JComboBox();
        jcOpcion = new javax.swing.JComboBox();
        jlTitulo = new javax.swing.JLabel();
        jlTurnoActual = new javax.swing.JLabel();
        jlPuntos = new javax.swing.JLabel();
        BTN_CartaAnfitrion = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        BTN_CartaJugador = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtMesa = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jlJugador1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jlJugador1.setText("Jugador1");

        jlJugador2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jlJugador2.setText("Jugador2");

        jPanel2.setOpaque(false);

        jbAbandonar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_cancelar_roll.png"))); // NOI18N
        jbAbandonar.setEnabled(false);
        jbAbandonar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbAbandonar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_cancelar.png"))); // NOI18N
        jbAbandonar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAbandonarActionPerformed(evt);
            }
        });

        jbConsultar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_ConsultarInforme.png"))); // NOI18N
        jbConsultar.setEnabled(false);
        jbConsultar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbConsultarActionPerformed(evt);
            }
        });

        jbRealizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_realizarJugada.png"))); // NOI18N
        jbRealizar.setEnabled(false);
        jbRealizar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbRealizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbRealizarActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_repartirCartas.png"))); // NOI18N
        jButton2.setEnabled(false);
        jButton2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jPanel1.setOpaque(false);

        jcCaracteristica.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-----------", "Duracion de Pelicula", "Galardones Ganados", "Año de Lanzamiento", "Dinero Recaudado", "Presupuesto" }));
        jcCaracteristica.setEnabled(false);

        jcOpcion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-----", "A la Mayor", "A la Menor" }));
        jcOpcion.setEnabled(false);

        jlTitulo.setText("Puntos:");

        jlTurnoActual.setOpaque(true);

        BTN_CartaAnfitrion.setBorder(null);
        BTN_CartaAnfitrion.setBorderPainted(false);
        BTN_CartaAnfitrion.setContentAreaFilled(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jcCaracteristica, javax.swing.GroupLayout.Alignment.LEADING, 0, 227, Short.MAX_VALUE)
                    .addComponent(BTN_CartaAnfitrion, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jlTitulo)
                        .addGap(41, 41, 41)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jlTurnoActual, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
                            .addComponent(jlPuntos, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jcOpcion, javax.swing.GroupLayout.Alignment.LEADING, 0, 227, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(BTN_CartaAnfitrion, javax.swing.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcCaracteristica, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jcOpcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlTitulo)
                    .addComponent(jlPuntos, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jlTurnoActual, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel3.setOpaque(false);

        BTN_CartaJugador.setBorder(null);
        BTN_CartaJugador.setBorderPainted(false);
        BTN_CartaJugador.setContentAreaFilled(false);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(BTN_CartaJugador, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(BTN_CartaJugador, javax.swing.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jProgressBar1, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                    .addComponent(jbAbandonar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jbRealizar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jbConsultar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(148, 148, 148))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbAbandonar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbConsultar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbRealizar))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jtMesa.setColumns(20);
        jtMesa.setEditable(false);
        jtMesa.setRows(5);
        jScrollPane1.setViewportView(jtMesa);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(375, 375, 375)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(363, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(148, 148, 148)
                .addComponent(jlJugador2, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
                .addGap(236, 236, 236)
                .addComponent(jlJugador1)
                .addGap(258, 258, 258))
            .addGroup(layout.createSequentialGroup()
                .addGap(94, 94, 94)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(82, 82, 82))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlJugador1)
                            .addComponent(jlJugador2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(253, 253, 253))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-800)/2, (screenSize.height-600)/2, 800, 600);
    }// </editor-fold>//GEN-END:initComponents
    private void jbAbandonarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAbandonarActionPerformed
        // TODO add your handling code here:
        this.dispose();
        socket.send("a3");

        try {
            this.ij.dispose();
        } catch (Exception e) {
        }


}//GEN-LAST:event_jbAbandonarActionPerformed

    private void jbConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbConsultarActionPerformed
        // TODO add your handling code here:
        ArrayList<String> jugadores = new ArrayList<String>();
        ArrayList<String> puntajes = new ArrayList<String>();
        jugadores.add(this.jlJugador1.getText());
        jugadores.add("Anfitrion");

        puntajes.add("" + this.puntosJugador1);
        puntajes.add("" + this.puntosAlfitrion);

        ij = new InformeJuego(jugadores, puntajes, empates);
        ij.setVisible(true);

}//GEN-LAST:event_jbConsultarActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:

        juego = new ArrayList<Carta>(baraja.repartirCartas());
        for (int i = 0; i < juego.size(); i++) {
            if (i < 17) {
                alfitrion.add(juego.get(i));
            } else {
                jugador1.add(juego.get(i));
            }
        }

        //carga de imágenes ****************************************************
        ImageIcon imagenFondo = new ImageIcon();
        ImageIcon imagenFondoR = new ImageIcon();
        imagenFondo = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURL()));
        imagenFondoR = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURLR()));
        this.BTN_CartaAnfitrion.setIcon(imagenFondo);
        this.BTN_CartaAnfitrion.setRolloverIcon(imagenFondoR);

        ImageIcon imagenFondo2 = new ImageIcon();
        ImageIcon imagenFondo2R = new ImageIcon();
        imagenFondo2 = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURL()));
        imagenFondo2R = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURLR()));
        this.BTN_CartaJugador.setIcon(imagenFondo2);
        this.BTN_CartaJugador.setRolloverIcon(imagenFondo2R);
        //Fin carga Imagenes****************************************************

        socket.send("1" + jugador1.get(0).getNombrePelicula());
        socket.send("2" + alfitrion.get(0).getNombrePelicula());

        boolean empieza = baraja.esta1A(alfitrion);
        if (empieza) {
            this.jlTurnoActual.setText("Alfitrion");
            JOptionPane.showMessageDialog(null, "Empieza Alfitrion", "TURNO", JOptionPane.INFORMATION_MESSAGE);
            this.jlTurnoActual.setText("ALFITRION");
            socket.send("3");
            jbRealizar.setEnabled(true);
            jcCaracteristica.setEnabled(true);
            jcOpcion.setEnabled(true);
        } else {
            this.jlTurnoActual.setText("jugador1");
            JOptionPane.showMessageDialog(null, "Empieza Jugador1", "TURNO", JOptionPane.INFORMATION_MESSAGE);
            this.jlTurnoActual.setText("JUGADOR 1");
            socket.send("4");
            jbRealizar.setEnabled(false);
            jcCaracteristica.setEnabled(false);
            jcOpcion.setEnabled(false);
        }

        jbAbandonar.setEnabled(true);
        jbConsultar.setEnabled(true);


        this.jButton2.setEnabled(false);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jbRealizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRealizarActionPerformed
        // TODO add your handling code here:
        System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
        System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

        if ((jcCaracteristica.getSelectedIndex() == 0) || (jcOpcion.getSelectedIndex() == 0)) {
            JOptionPane.showMessageDialog(null, "Seleccione una caracteristica y apuesta", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            System.out.println("*********************PASO 1*************************");
        } else {
            if (jugador1.size() == 0 || alfitrion.size() == 0) {
                if (jugador1.size() == 0) {
                    System.out.println("*********************PASO 1.1*************************");
                    this.puntosAlfitrion += 50;
                    socket.send("a1" + puntosAlfitrion);
                    JOptionPane.showMessageDialog(null, "Anfitrion", "GANADOR", JOptionPane.INFORMATION_MESSAGE);
                    socket.send("7");

                    this.dispose();
                    this.gc.setVisible(true);
                    
                } else {
                    System.out.println("*********************PASO 1.2*************************");
                    this.puntosJugador1 += 50;
                    socket.send("a0" + puntosJugador1);
                    JOptionPane.showMessageDialog(null, "Jugador1", "GANADOR", JOptionPane.INFORMATION_MESSAGE);
                    socket.send("8");
                    this.dispose();
                      this.gc.setVisible(true);
                }
            } else {
                System.out.println("*********************PASO 2*************************");
                this.jtMesa.setText("");
                this.jtMesa.setBackground(Color.WHITE);
                this.jlJugador1.setForeground(Color.BLACK);
                int ganador = 0;

                jugada.add(jugador1.get(0));
                jugada.add(alfitrion.get(0));

                //carga de imágenes ****************************************************
                ImageIcon imagenFondo = new ImageIcon();
                ImageIcon imagenFondoR = new ImageIcon();
                imagenFondo = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURL()));
                imagenFondoR = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURLR()));
                this.BTN_CartaAnfitrion.setIcon(imagenFondo);
                this.BTN_CartaAnfitrion.setRolloverIcon(imagenFondoR);

                ImageIcon imagenFondo2 = new ImageIcon();
                ImageIcon imagenFondo2R = new ImageIcon();
                imagenFondo2 = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURL()));
                imagenFondo2R = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURLR()));
                this.BTN_CartaJugador.setIcon(imagenFondo2);
                this.BTN_CartaJugador.setRolloverIcon(imagenFondo2R);
                //Fin carga Imagenes****************************************************

                socket.send("A4" + jugador1.get(0).getNombrePelicula());
                socket.send("A5" + alfitrion.get(0).getNombrePelicula());

                this.jtMesa.setText(jugada.get(0).getNumero() + jugada.get(0).getLetra());
                this.jtMesa.append(jugada.get(1).getNumero() + jugada.get(1).getLetra());
                socket.send("5" + this.jtMesa.getText());

                if (this.jcOpcion.getSelectedIndex() == 1) {
                    System.out.println("*********************PASO 3*************************");
                    ganador = baraja.jugadaModalidad2(jugada, this.jcCaracteristica.getSelectedItem().toString(), true);

                    if (ganador == -2) {
                        System.out.println("*********************PASO 4*************************");
                        empate();
                        empates++;
                        return;
                    } else if (ganador == 0) {
                        System.out.println("*********************PASO 5*************************");
                        this.jlJugador1.setForeground(Color.BLUE);

                        jugador1.remove(0);
                        alfitrion.remove(0);
                        jugador1.add(jugada.get(0));
                        jugador1.add(jugada.get(1));

                        //carga de imágenes ****************************************************
                        imagenFondo = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURL()));
                        imagenFondoR = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURLR()));
                        this.BTN_CartaAnfitrion.setIcon(imagenFondo);
                        this.BTN_CartaAnfitrion.setRolloverIcon(imagenFondoR);

                        imagenFondo2 = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURL()));
                        imagenFondo2R = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURLR()));
                        this.BTN_CartaJugador.setIcon(imagenFondo2);
                        this.BTN_CartaJugador.setRolloverIcon(imagenFondo2R);
                        //Fin carga Imagenes****************************************************

                        socket.send("A4" + jugador1.get(0).getNombrePelicula());
                        socket.send("A5" + alfitrion.get(0).getNombrePelicula());

                        this.puntosJugador1 += 4;
                        socket.send("a0" + puntosJugador1);
                        socket.send("6" + 0);
                        //Sumar puntos
                        this.jlTurnoActual.setText("JUGADOR1");
                        //this.jtMesa.setText("");
                        //this.jtMesa.setBackground(Color.WHITE);
                        //this.jlJugador1.setForeground(Color.BLACK);
                        this.jbRealizar.setEnabled(false);
                        this.jcCaracteristica.setEnabled(false);
                        this.jcOpcion.setEnabled(false);
                    } else {

                        System.out.println("*********************PASO 6*************************");
                        this.jtMesa.setBackground(Color.GREEN);
                        alfitrion.remove(0);
                        jugador1.remove(0);
                        alfitrion.add(jugada.get(0));
                        alfitrion.add(jugada.get(1));

                        //carga de imágenes ****************************************************
                        imagenFondo = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURL()));
                        imagenFondoR = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURLR()));
                        this.BTN_CartaAnfitrion.setIcon(imagenFondo);
                        this.BTN_CartaAnfitrion.setRolloverIcon(imagenFondoR);

                        imagenFondo2 = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURL()));
                        imagenFondo2R = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURLR()));
                        this.BTN_CartaJugador.setIcon(imagenFondo2);
                        this.BTN_CartaJugador.setRolloverIcon(imagenFondo2R);
                        //Fin carga Imagenes****************************************************

                        //Envio de informacion al Tablero_1*********************
                        socket.send("A4" + jugador1.get(0).getNombrePelicula());
                        socket.send("A5" + alfitrion.get(0).getNombrePelicula());
                        //******************************************************

                        this.puntosAlfitrion += 4;
                        socket.send("a1" + puntosAlfitrion);
                        socket.send("6" + 1);
                    //Sumar puntos
                    }
                } else {
                    System.out.println("*********************PASO 7*************************");
                    ganador = baraja.jugadaModalidad2(jugada, this.jcCaracteristica.getSelectedItem().toString(), false);
                    if (ganador == -2) {
                        System.out.println("*********************PASO 8*************************");
                        empate();
                        empates++;
                        return;
                    } else if (ganador == 0) {
                        System.out.println("*********************PASO 9*************************");
                        this.jlJugador1.setForeground(Color.BLUE);
                        jugador1.remove(0);
                        alfitrion.remove(0);
                        jugador1.add(jugada.get(0));
                        jugador1.add(jugada.get(1));

                        //carga de imágenes ****************************************************
                        imagenFondo = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURL()));
                        imagenFondoR = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURLR()));
                        this.BTN_CartaAnfitrion.setIcon(imagenFondo);
                        this.BTN_CartaAnfitrion.setRolloverIcon(imagenFondoR);

                        imagenFondo2 = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURL()));
                        imagenFondo2R = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURLR()));
                        this.BTN_CartaJugador.setIcon(imagenFondo2);
                        this.BTN_CartaJugador.setRolloverIcon(imagenFondo2R);
                        //Fin carga Imagenes****************************************************

                        //Envio de informacion al Tablero_1*********************
                        socket.send("A4" + jugador1.get(0).getNombrePelicula());
                        socket.send("A5" + alfitrion.get(0).getNombrePelicula());
                        //******************************************************

                        this.puntosJugador1 += 4;
                        socket.send("a0" + puntosJugador1);
                        socket.send("6" + 0);
                        //Sumar puntos
                        //Sumar puntos
                        this.jlTurnoActual.setText("JUGADOR1");
                        //this.jtMesa.setText("");
                        //this.jtMesa.setBackground(Color.WHITE);
                        //this.jlJugador1.setForeground(Color.BLACK);
                        this.jbRealizar.setEnabled(false);
                        this.jcCaracteristica.setEnabled(false);
                        this.jcOpcion.setEnabled(false);
                    } else {
                        System.out.println("*********************PASO 10*************************");
                        this.jtMesa.setBackground(Color.GREEN);
                        //Sumar puntos
                        alfitrion.remove(0);
                        jugador1.remove(0);
                        alfitrion.add(jugada.get(0));
                        alfitrion.add(jugada.get(1));

                        //carga de imágenes ****************************************************
                        imagenFondo = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURL()));
                        imagenFondoR = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURLR()));
                        this.BTN_CartaAnfitrion.setIcon(imagenFondo);
                        this.BTN_CartaAnfitrion.setRolloverIcon(imagenFondoR);

                        imagenFondo2 = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURL()));
                        imagenFondo2R = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURLR()));
                        this.BTN_CartaJugador.setIcon(imagenFondo2);
                        this.BTN_CartaJugador.setRolloverIcon(imagenFondo2R);
                        //Fin carga Imagenes****************************************************

                        //Envio de informacion al Tablero_1*********************
                        socket.send("A4" + jugador1.get(0).getNombrePelicula());
                        socket.send("A5" + alfitrion.get(0).getNombrePelicula());
                        //******************************************************

                        this.puntosAlfitrion += 4;
                        socket.send("a1" + puntosAlfitrion);
                        socket.send("6" + 1);
                    }
                }


            }

            jugada.clear();
            this.jlPuntos.setText("" + this.puntosAlfitrion);


        }
    }//GEN-LAST:event_jbRealizarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        JFrame.setDefaultLookAndFeelDecorated(false);
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Tablero().setVisible(true);
            }
        });
    }

    public ArrayList<Carta> getAlfitrion() {
        return alfitrion;
    }

    public void setAlfitrion(ArrayList<Carta> alfitrion) {
        this.alfitrion = alfitrion;
    }

    public Baraja getBaraja() {
        return baraja;
    }

    public void setBaraja(Baraja baraja) {
        this.baraja = baraja;
    }

    public JButton getJButton2() {
        return jButton2;
    }

    public void setJButton2(JButton jButton2) {
        this.jButton2 = jButton2;
    }

    public JScrollPane getJScrollPane1() {
        return jScrollPane1;
    }

    public void setJScrollPane1(JScrollPane jScrollPane1) {
        this.jScrollPane1 = jScrollPane1;
    }

    public JButton getJbAbandonar() {
        return jbAbandonar;
    }

    public void setJbAbandonar(JButton jbAbandonar) {
        this.jbAbandonar = jbAbandonar;
    }

    public JButton getJbConsultar() {
        return jbConsultar;
    }

    public void setJbConsultar(JButton jbConsultar) {
        this.jbConsultar = jbConsultar;
    }

    public JButton getJbRealizar() {
        return jbRealizar;
    }

    public void setJbRealizar(JButton jbRealizar) {
        this.jbRealizar = jbRealizar;
    }

    public JComboBox getJcCaracteristica() {
        return jcCaracteristica;
    }

    public void setJcCaracteristica(JComboBox jcCaracteristica) {
        this.jcCaracteristica = jcCaracteristica;
    }

    public JComboBox getJcOpcion() {
        return jcOpcion;
    }

    public void setJcOpcion(JComboBox jcOpcion) {
        this.jcOpcion = jcOpcion;
    }


    public JLabel getJlJugador1() {
        return jlJugador1;
    }

    public void setJlJugador1(JLabel jlJugador1) {
        this.jlJugador1 = jlJugador1;
    }

    public JLabel getJlJugador2() {
        return jlJugador2;
    }

    public void setJlJugador2(JLabel jlJugador2) {
        this.jlJugador2 = jlJugador2;
    }

    public JLabel getJlPuntos() {
        return jlPuntos;
    }

    public void setJlPuntos(JLabel jlPuntos) {
        this.jlPuntos = jlPuntos;
    }

    public JLabel getJlTitulo() {
        return jlTitulo;
    }

    public void setJlTitulo(JLabel jlTitulo) {
        this.jlTitulo = jlTitulo;
    }

    public JTextArea getJtMesa() {
        return jtMesa;
    }

    public void setJtMesa(JTextArea jtMesa) {
        this.jtMesa = jtMesa;
    }

    public ArrayList<Carta> getJuego() {
        return juego;
    }

    public void setJuego(ArrayList<Carta> juego) {
        this.juego = juego;
    }

    public ArrayList<Carta> getJugador1() {
        return jugador1;
    }

    public void setJugador1(ArrayList<Carta> jugador1) {
        this.jugador1 = jugador1;
    }

    public ArrayList<Carta> getJugador2() {
        return jugador2;
    }

    public void setJugador2(ArrayList<Carta> jugador2) {
        this.jugador2 = jugador2;
    }

    public ArrayList<Carta> getJugador3() {
        return jugador3;
    }

    public void setJugador3(ArrayList<Carta> jugador3) {
        this.jugador3 = jugador3;
    }

    public SocketServer getSocket() {
        return socket;
    }

    public void setSocket(SocketServer socket) {
        this.socket = socket;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BTN_CartaAnfitrion;
    private javax.swing.JButton BTN_CartaJugador;
    private javax.swing.JButton jButton2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbAbandonar;
    private javax.swing.JButton jbConsultar;
    private javax.swing.JButton jbRealizar;
    private javax.swing.JComboBox jcCaracteristica;
    private javax.swing.JComboBox jcOpcion;
    private javax.swing.JLabel jlJugador1;
    private javax.swing.JLabel jlJugador2;
    private javax.swing.JLabel jlPuntos;
    private javax.swing.JLabel jlTitulo;
    private javax.swing.JLabel jlTurnoActual;
    private javax.swing.JTextArea jtMesa;
    // End of variables declaration//GEN-END:variables

    public void iniciar(int puerto) {
        System.out.println("ACAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + puerto);
        System.out.println("ACAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + puerto);
        this.jProgressBar1.setIndeterminate(true);

        int p = 0;
        p = puerto;
        socket = new SocketServer(p, this);
        socket.send("Hola soy servidor");
        this.jButton2.setEnabled(true);
        this.jlPuntos.setText("" + this.puntosAlfitrion);
    }

    public void empate() {
        this.jtMesa.setBackground(Color.PINK);
        socket.send("9");
        JOptionPane.showMessageDialog(null, "Empate", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
        int ganador2 = 0;
        jugada.add(0, jugador1.get(1));
        jugada.add(1, alfitrion.get(1));
        this.jtMesa.setText(jugada.get(0).getNumero() + jugada.get(0).getLetra());
        this.jtMesa.append(jugada.get(1).getNumero() + jugada.get(1).getLetra());
        socket.send("5" + this.jtMesa.getText());
        ganador2 = baraja.jugadaModalidad2(jugada, this.jcCaracteristica.getSelectedItem().toString(), true);

        if (this.jcOpcion.getSelectedIndex() == 1) {
            ganador2 = baraja.jugadaModalidad2(jugada, this.jcCaracteristica.getSelectedItem().toString(), true);
            if (ganador2 == 0) {
                this.jlJugador1.setForeground(Color.BLUE);

                jugador1.remove(0);
                jugador1.remove(1);
                alfitrion.remove(0);
                alfitrion.remove(1);
                jugador1.add(jugada.get(0));
                jugador1.add(jugada.get(1));
                jugador1.add(jugada.get(2));
                jugador1.add(jugada.get(3));
                socket.send("6" + 0);
                //Sumar puntos
                this.jlTurnoActual.setText("JUGADOR1");
                //this.jtMesa.setText("");
                //this.jtMesa.setBackground(Color.WHITE);
                //this.jlJugador1.setForeground(Color.BLACK);
                this.jbRealizar.setEnabled(false);
                this.jcCaracteristica.setEnabled(false);
                this.jcOpcion.setEnabled(false);
            } else {
                this.jtMesa.setBackground(Color.GREEN);
                alfitrion.remove(0);
                alfitrion.remove(1);
                jugador1.remove(0);
                jugador1.remove(1);
                alfitrion.add(jugada.get(0));
                alfitrion.add(jugada.get(1));
                alfitrion.add(jugada.get(2));
                alfitrion.add(jugada.get(3));
                socket.send("6" + 1);
            //Sumar puntos
            }
        } else {

            ganador2 = baraja.jugadaModalidad2(jugada, this.jcCaracteristica.getSelectedItem().toString(), false);
            if (ganador2 == 0) {
                this.jlJugador1.setForeground(Color.BLUE);
                jugador1.remove(0);
                jugador1.remove(1);
                alfitrion.remove(0);
                alfitrion.remove(1);
                jugador1.add(jugada.get(0));
                jugador1.add(jugada.get(1));
                jugador1.add(jugada.get(2));
                jugador1.add(jugada.get(3));
                socket.send("6" + 0);
                //Sumar puntos
                //Sumar puntos
                this.jlTurnoActual.setText("JUGADOR1");
                //this.jtMesa.setText("");
                //this.jtMesa.setBackground(Color.WHITE);
                //this.jlJugador1.setForeground(Color.BLACK);
                this.jbRealizar.setEnabled(false);
                this.jcCaracteristica.setEnabled(false);
                this.jcOpcion.setEnabled(false);
            } else {
                this.jtMesa.setBackground(Color.GREEN);
                //Sumar puntos
                jugador1.remove(0);
                jugador1.remove(1);
                alfitrion.remove(0);
                alfitrion.remove(1);
                alfitrion.add(jugada.get(0));
                alfitrion.add(jugada.get(1));
                alfitrion.add(jugada.get(2));
                alfitrion.add(jugada.get(3));
                socket.send("6" + 1);
            }
        }




        jugada.clear();
    }

    public void receiveData(String data) {

        System.out.println("RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR");
        System.out.println("RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR");

        System.out.println(data);

        ImageIcon imagenFondo = new ImageIcon();
        ImageIcon imagenFondoR = new ImageIcon();
        ImageIcon imagenFondo2 = new ImageIcon();
        ImageIcon imagenFondo2R = new ImageIcon();

        if (data.substring(0, 1).equalsIgnoreCase("1")) {
            System.out.println("*********************PASO 11*************************");
            this.s1 = data.substring(1);
        }


        if (data.substring(0, 1).equalsIgnoreCase("2")) {
            System.out.println("*********************PASO 12*************************");

            if (jugador1.size() == 0 || alfitrion.size() == 0) {
                System.out.println("*********************PASO 13*************************");
                if (jugador1.size() == 0) {
                    System.out.println("*********************PASO 14*************************");
                    this.puntosAlfitrion += 50;
                    socket.send("a1" + puntosAlfitrion);
                    JOptionPane.showMessageDialog(null, "Anfitrion", "GANADOR", JOptionPane.INFORMATION_MESSAGE);
                    socket.send("7");
                    this.dispose();
                } else {
                    System.out.println("*********************PASO 15*************************");
                    this.puntosJugador1 += 50;
                    socket.send("a0" + puntosJugador1);
                    JOptionPane.showMessageDialog(null, "Jugador1", "GANADOR", JOptionPane.INFORMATION_MESSAGE);
                    socket.send("8");
                    this.dispose();
                }
            } else {
                System.out.println("*********************PASO 16*************************");
                this.jtMesa.setText("");
                this.jtMesa.setBackground(Color.WHITE);
                this.jlJugador1.setForeground(Color.BLACK);
                int ganador = 0;
                jugada.add(jugador1.get(0));
                jugada.add(alfitrion.get(0));

                //carga de imágenes ****************************************************
                imagenFondo = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURL()));
                imagenFondoR = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURLR()));
                this.BTN_CartaAnfitrion.setIcon(imagenFondo);
                this.BTN_CartaAnfitrion.setRolloverIcon(imagenFondoR);

                imagenFondo2 = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURL()));
                imagenFondo2R = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURLR()));
                this.BTN_CartaJugador.setIcon(imagenFondo2);
                this.BTN_CartaJugador.setRolloverIcon(imagenFondo2R);
                //Fin carga Imagenes****************************************************

                socket.send("A4" + jugador1.get(0).getNombrePelicula());
                socket.send("A5" + alfitrion.get(0).getNombrePelicula());

                this.jtMesa.setText(jugada.get(0).getNumero() + jugada.get(0).getLetra());
                this.jtMesa.append(jugada.get(1).getNumero() + jugada.get(1).getLetra());
                socket.send("5" + this.jtMesa.getText());
                if (data.substring(1).equalsIgnoreCase("1")) {
                    System.out.println("*********************PASO 17*************************");
                    ganador = baraja.jugadaModalidad2(jugada, s1, true);
                    if (ganador == -2) {
                        System.out.println("*********************PASO 18*************************");
                        empate();
                        empates++;
                        return;
                    } else if (ganador == 0) {
                        System.out.println("*********************PASO 19*************************");
                        this.jlJugador1.setForeground(Color.BLUE);
                        jugador1.remove(0);
                        alfitrion.remove(0);
                        jugador1.add(jugada.get(0));
                        jugador1.add(jugada.get(1));

                        //carga de imágenes ****************************************************
                        imagenFondo = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURL()));
                        imagenFondoR = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURLR()));
                        this.BTN_CartaAnfitrion.setIcon(imagenFondo);
                        this.BTN_CartaAnfitrion.setRolloverIcon(imagenFondoR);

                        imagenFondo2 = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURL()));
                        imagenFondo2R = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURLR()));
                        this.BTN_CartaJugador.setIcon(imagenFondo2);
                        this.BTN_CartaJugador.setRolloverIcon(imagenFondo2R);
                        //Fin carga Imagenes****************************************************

                        socket.send("A4" + jugador1.get(0).getNombrePelicula());
                        socket.send("A5" + alfitrion.get(0).getNombrePelicula());

                        this.puntosJugador1 += 4;
                        socket.send("a0" + puntosJugador1);
                        socket.send("6" + 0);
                    //Sumar puntos
                    } else {
                        System.out.println("*********************PASO 20*************************");
                        this.jtMesa.setBackground(Color.BLUE);
                        alfitrion.remove(0);
                        jugador1.remove(0);
                        alfitrion.add(jugada.get(0));
                        alfitrion.add(jugada.get(1));

                        //carga de imágenes ****************************************************
                        imagenFondo = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURL()));
                        imagenFondoR = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURLR()));
                        this.BTN_CartaAnfitrion.setIcon(imagenFondo);
                        this.BTN_CartaAnfitrion.setRolloverIcon(imagenFondoR);

                        imagenFondo2 = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURL()));
                        imagenFondo2R = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURLR()));
                        this.BTN_CartaJugador.setIcon(imagenFondo2);
                        this.BTN_CartaJugador.setRolloverIcon(imagenFondo2R);
                        //Fin carga Imagenes****************************************************

                        socket.send("A4" + jugador1.get(0).getNombrePelicula());
                        socket.send("A5" + alfitrion.get(0).getNombrePelicula());

                        this.puntosAlfitrion += 4;
                        socket.send("a1" + puntosAlfitrion);
                        socket.send("6" + 1);
                        //Sumar puntos
                        this.jlTurnoActual.setText("ANFITRION");
                        this.jlTurnoActual.setForeground(Color.RED);

                        this.jbRealizar.setEnabled(true);
                        this.jcCaracteristica.setEnabled(true);
                        this.jcOpcion.setEnabled(true);

                    }
                } else {
                    System.out.println("*********************PASO 21*************************");
                    ganador = baraja.jugadaModalidad2(jugada, s1, false);
                    if (ganador == -2) {
                        System.out.println("*********************PASO 22*************************");
                        empate();
                        empates++;
                        return;
                    } else if (ganador == 0) {
                        System.out.println("*********************PASO 23*************************");
                        this.jlJugador1.setForeground(Color.BLUE);
                        jugador1.remove(0);
                        alfitrion.remove(0);
                        jugador1.add(jugada.get(0));
                        jugador1.add(jugada.get(1));

                        //carga de imágenes ****************************************************
                        imagenFondo = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURL()));
                        imagenFondoR = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURLR()));
                        this.BTN_CartaAnfitrion.setIcon(imagenFondo);
                        this.BTN_CartaAnfitrion.setRolloverIcon(imagenFondoR);

                        imagenFondo2 = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURL()));
                        imagenFondo2R = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURLR()));
                        this.BTN_CartaJugador.setIcon(imagenFondo2);
                        this.BTN_CartaJugador.setRolloverIcon(imagenFondo2R);
                        //Fin carga Imagenes****************************************************

                        socket.send("A4" + jugador1.get(0).getNombrePelicula());
                        socket.send("A5" + alfitrion.get(0).getNombrePelicula());

                        this.puntosJugador1 += 4;
                        socket.send("a0" + puntosJugador1);
                        socket.send("6" + 0);
                    //Sumar puntos
                    } else {
                        System.out.println("*********************PASO 24*************************");
                        this.jtMesa.setBackground(Color.BLUE);
                        //Sumar puntos
                        alfitrion.remove(0);
                        jugador1.remove(0);
                        alfitrion.add(jugada.get(0));
                        alfitrion.add(jugada.get(1));

                        //carga de imágenes ****************************************************
                        imagenFondo = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURL()));
                        imagenFondoR = new ImageIcon(getClass().getResource(this.alfitrion.get(0).getURLR()));
                        this.BTN_CartaAnfitrion.setIcon(imagenFondo);
                        this.BTN_CartaAnfitrion.setRolloverIcon(imagenFondoR);

                        imagenFondo2 = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURL()));
                        imagenFondo2R = new ImageIcon(getClass().getResource(this.jugador1.get(0).getURLR()));
                        this.BTN_CartaJugador.setIcon(imagenFondo2);
                        this.BTN_CartaJugador.setRolloverIcon(imagenFondo2R);
                        //Fin carga Imagenes****************************************************

                        socket.send("A4" + jugador1.get(0).getNombrePelicula());
                        socket.send("A5" + alfitrion.get(0).getNombrePelicula());
                        this.puntosAlfitrion += 4;
                        socket.send("a1" + puntosAlfitrion);
                        socket.send("6" + 1);
                        this.jlTurnoActual.setText("ANFITRION");
                        this.jlTurnoActual.setForeground(Color.RED);

                        this.jbRealizar.setEnabled(true);
                        this.jcCaracteristica.setEnabled(true);
                        this.jcOpcion.setEnabled(true);

                    }
                }
                jugada.clear();
                this.jlPuntos.setText("" + this.puntosAlfitrion);

            }


        }

        if (data.substring(0, 1).equalsIgnoreCase("3")) {
            System.out.println("*********************PASO 25*************************");
            JOptionPane.showMessageDialog(null, "El Jugador1 Abando la partida!", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            this.dispose();
            try {
                this.ij.dispose();
            } catch (Exception e) {
            }
        }

    }
}

